import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ModalDirective} from "ngx-bootstrap";
import {AliyunOssOutputUrl, tuikeSystemUrl} from "../../../config/api";
import {HttpService} from "../../lib/service/http.service";
import {Headers, RequestOptions} from "@angular/http";
import * as moment from 'moment';
import {Router} from "@angular/router";

@Component({
  selector: 'with-draw',
  templateUrl: './withdraw.component.html',
  styleUrls: ['./withdraw.component.scss']
})
export class WithdrawComponent implements OnInit {
  realname="";
  mobile="";
  alipayAccount="";
  realnameShow="";
  mobileShow="";
  alipayAccountShow="";
  withDrawList=[];
  tuikeSystemUrl=tuikeSystemUrl;
  page=1;
  pageSize=20;
  total=0;
  _isSpinning=false;
  downUrl="";
  constructor(private httpService: HttpService, private el: ElementRef, private router: Router) {

  }
  getDownUrl(){
    let url = `${tuikeSystemUrl}/api/v1/admin/member_point_withdraw/index?export=1`;
    if(!this.mobile.trim()&&!this.realname.trim()&&!this.alipayAccount.trim()){
      url+="&page="+this.page+"&pageSize="+this.pageSize;
    }else{
      if(this.mobile.trim()){
        url+="&mobile="+this.mobile.trim();
      }
      if( this.realname.trim() ){
        url+="&realname="+this.realname.trim();
      }
      if (this.alipayAccount.trim() ) {
        url+="&alipayAccount="+this.alipayAccount.trim();
      }
    }
    return url;
  }
  getList(){
    let url=`${tuikeSystemUrl}/api/v1/admin/member_point_withdraw/index?page=`+this.page+"&pageSize="+this.pageSize;
    if(this.mobile.trim()){
      url+="&mobile="+this.mobile.trim();
    }
    if(this.realname.trim()){
      url+="&realname="+this.realname.trim();
    }
    if(this.alipayAccount.trim()){
      url+="&alipayAccount="+this.alipayAccount.trim();
    }
    console.log(url);
    this.downUrl=this.getDownUrl();
    console.log(this.downUrl);
    this._isSpinning=true;
    this.httpService.httpGetAuth(url).subscribe(res => {
      if(res.code === 200) {
        this.withDrawList=res.data.data;
        this.total=res.data.total;
      }
      this._isSpinning=false;
    });
  }
  pageChanged(e){
    window.scrollTo(0, 0);
    console.log(e);
    this.page=e.page;
    this.getList();
  }
  ngOnInit() {
    this.getList();
  }
  reset(){
    this.realname="";
    this.mobile="";
    this.alipayAccount="";
    this.realnameShow="";
    this.mobileShow="";
    this.alipayAccountShow="";
    this.getList();
  }

  keyDown(e) {
    if(e.code == 'Enter') {
      this.search();
    }
  }
  search(){
    this.realname=this.realnameShow;
    this.mobile=this.mobileShow;
    this.alipayAccount=this.alipayAccountShow;
    this.getList();
  }

}
